<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import musicSongFile from '@/api/music/musicSongFile'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()



const switchStatus = (statusValue, id, statusName) => {
  musicSongFile.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'music_song_file',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'drawer',
    width: 600
  },
  api: musicSongFile.getList,
  recycleApi: musicSongFile.getRecycleList,
  add: {
    show: true,
    api: musicSongFile.save,
    auth: ['music:songFile:save']
  },
  edit: {
    show: true,
    api: musicSongFile.update,
    auth: ['music:songFile:update']
  },
  delete: {
    show: true,
    api: musicSongFile.deletes,
    auth: ['music:songFile:delete'],
    realApi: musicSongFile.realDeletes,
    realAuth: ['music:songFile:realDeletes']
  },
  recovery: {
    show: true,
    api: musicSongFile.recoverys,
    auth: ['music:songFile:recovery']
  }
})

const columns = reactive([
  {
    title: "",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入"
    }
  },
  {
    title: "歌曲 ID",
    dataIndex: "song_id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入歌曲 ID"
    }
  },
  {
    title: "文件名",
    dataIndex: "file_name",
    formType: "input",
    type: "file",
    multiple: false
  },
  {
    title: "歌曲地址",
    dataIndex: "file_url",
    formType: "input",
    type: "file",
    multiple: false
  },
  {
    title: "歌曲下载密码",
    dataIndex: "pwd",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入歌曲下载密码"
    }
  },
  {
    title: "文件类型",
    dataIndex: "file_type",
    formType: "select",
    commonRules: {
      required: true,
      message: "请输入文件类型"
    },
    type: "file",
    multiple: false
  },
  {
    title: "文件字节大小",
    dataIndex: "size",
    formType: "input",
    search: true
  },
  {
    title: "比特率",
    dataIndex: "bit_rate",
    formType: "input",
    search: true
  },
  {
    title: "来源",
    dataIndex: "source",
    formType: "input",
    search: true
  },
  {
    title: "状态",
    dataIndex: "status",
    formType: "select",
    search: true,
    commonRules: {
      required: true,
      message: "请输入状态"
    },
    dict: {
      data: [
        {
          label: "否",
          value: "0"
        },
        {
          label: "是",
          value: "1"
        }
      ],
      translation: true
    }
  },
  {
    title: "音乐时长/秒",
    dataIndex: "duration",
    formType: "input-number",
    search: true
  },
  {
    title: "来源状态",
    dataIndex: "source_extend",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "存储位置",
    dataIndex: "storage",
    formType: "select",
    search: true,
    commonRules: {
      required: true,
      message: "请输入存储位置"
    },
    dict: {
      data: [
        {
          label: "七牛云",
          value: "qiniu"
        },
        {
          label: "夸克网盘",
          value: "kuake"
        },
        {
          label: "阿里网盘",
          value: "ali"
        },
        {
          label: "百度网盘",
          value: "baidu"
        }
      ],
      translation: true
    }
  },
  {
    title: "添加时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "最后更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  }
])
</script>
<script> export default { name: 'music:songFile' } </script>